package com.imut.lagain.exception;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 业务异常类
 * 用于处理业务逻辑中的异常情况
 */
public class BusinessException extends RuntimeException {
    private static final Logger log = LoggerFactory.getLogger(BusinessException.class);

    
    private final String code;
    private final String message;
    
    public BusinessException(String message) {
        super(message);
        this.code = "BUSINESS_ERROR";
        this.message = message;
    }
    
    public BusinessException(String code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }
    
    public BusinessException(String code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.message = message;
    }
    
    public String getCode() {
        return code;
    }
    
    @Override
    public String getMessage() {
        return message;
    }
    public static class UserNotFoundException extends BusinessException {
        public UserNotFoundException() {
            super("USER_NOT_FOUND", "用户不存在");
        }
        
        public UserNotFoundException(String message) {
            super("USER_NOT_FOUND", message);
        }
    }
    
    public static class CapsuleNotFoundException extends BusinessException {
        public CapsuleNotFoundException() {
            super("CAPSULE_NOT_FOUND", "时光胶囊不存在");
        }
        
        public CapsuleNotFoundException(String message) {
            super("CAPSULE_NOT_FOUND", message);
        }
    }
    
    public static class EntryNotFoundException extends BusinessException {
        public EntryNotFoundException() {
            super("ENTRY_NOT_FOUND", "记忆条目不存在");
        }
        
        public EntryNotFoundException(String message) {
            super("ENTRY_NOT_FOUND", message);
        }
    }
    
    public static class UnauthorizedException extends BusinessException {
        public UnauthorizedException() {
            super("UNAUTHORIZED", "未授权访问");
        }
        
        public UnauthorizedException(String message) {
            super("UNAUTHORIZED", message);
        }
    }
    
    public static class ForbiddenException extends BusinessException {
        public ForbiddenException() {
            super("FORBIDDEN", "禁止访问");
        }
        
        public ForbiddenException(String message) {
            super("FORBIDDEN", message);
        }
    }
    
    public static class InvalidParameterException extends BusinessException {
        public InvalidParameterException(String message) {
            super("INVALID_PARAMETER", message);
        }
    }
    
    public static class FileUploadException extends BusinessException {
        public FileUploadException(String message) {
            super("FILE_UPLOAD_ERROR", message);
        }
        
        public FileUploadException(String message, Throwable cause) {
            super("FILE_UPLOAD_ERROR", message, cause);
        }
    }
    
    public static class PasswordValidationException extends BusinessException {
        public PasswordValidationException() {
            super("PASSWORD_VALIDATION_FAILED", "密码验证失败");
        }
        
        public PasswordValidationException(String message) {
            super("PASSWORD_VALIDATION_FAILED", message);
        }
    }
    
    public static class CapsuleAccessException extends BusinessException {
        public CapsuleAccessException(String message) {
            super("CAPSULE_ACCESS_DENIED", message);
        }
    }
    
    public static class CapsuleSealedException extends BusinessException {
        public CapsuleSealedException() {
            super("CAPSULE_SEALED", "时光胶囊已封存，无法修改");
        }
        
        public CapsuleSealedException(String message) {
            super("CAPSULE_SEALED", message);
        }
    }
    
    public static class CapsuleNotOpenException extends BusinessException {
        public CapsuleNotOpenException() {
            super("CAPSULE_NOT_OPEN", "时光胶囊尚未到开启时间");
        }
        
        public CapsuleNotOpenException(String message) {
            super("CAPSULE_NOT_OPEN", message);
        }
    }
}
